package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.UserRegisterCensorAddDTO;
import org.jsola.hr.dto.UserRegisterCensorUpdateDTO;
import org.jsola.hr.entity.UserRegisterCensorDO;
import org.jsola.hr.query.UserRegisterCensorQuery;
import org.jsola.hr.service.IUserRegisterCensorService;
import org.jsola.hr.vo.UserRegisterCensorVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 注册审核表
 *
 * @author zhr
 */
@Component
public class UserRegisterCensorTestHelper extends BaseTestHelper {
    
    @Autowired
    private IUserRegisterCensorService userRegisterCensorService;

    /**
     * 生成add测试数据
     * @return UserRegisterCensorAddDTO
     */
    public UserRegisterCensorAddDTO getUserRegisterCensorAddDTO(){
        UserRegisterCensorAddDTO userRegisterCensorAddDTO = new UserRegisterCensorAddDTO();
        userRegisterCensorAddDTO.setCityName(getRandomValue("varchar",200));
        userRegisterCensorAddDTO.setName(getRandomValue("varchar",50));
        userRegisterCensorAddDTO.setGender(SafeKit.getInteger(getRandomValue("tinyint",4)));
        userRegisterCensorAddDTO.setCompanyName(getRandomValue("varchar",100));
        userRegisterCensorAddDTO.setPhone(getRandomValue("varchar",11));
        userRegisterCensorAddDTO.setEmail(getRandomValue("varchar",64));
        userRegisterCensorAddDTO.setLeaveMessage(getRandomValue("varchar",500));
        userRegisterCensorAddDTO.setRegisterReason(SafeKit.getInteger(getRandomValue("int",10)));
        userRegisterCensorAddDTO.setAuditStatus(SafeKit.getInteger(getRandomValue("int",10)));
        userRegisterCensorAddDTO.setDenialReason(getRandomValue("varchar",100));
        return userRegisterCensorAddDTO;
    }


    /**
     * 生成update测试数据
     * @return UserRegisterCensorUpdateDTO
     */
    public UserRegisterCensorUpdateDTO getUserRegisterCensorUpdateDTO(UserRegisterCensorVO userRegisterCensorVO){
        return userRegisterCensorService.selectDOById(userRegisterCensorVO.getId(), SITE_ID).to(UserRegisterCensorUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return UserRegisterCensorQuery
     */
    public UserRegisterCensorQuery getUserRegisterCensorQuery() {
        UserRegisterCensorQuery userRegisterCensorQuery = new UserRegisterCensorQuery();
        List<UserRegisterCensorDO> userRegisterCensorDOList = userRegisterCensorService.list(new UserRegisterCensorDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(userRegisterCensorDOList)) {
            UserRegisterCensorDO userRegisterCensorDO = userRegisterCensorDOList.get(0);
            userRegisterCensorQuery = userRegisterCensorDO.to(UserRegisterCensorQuery.class);
        }
        return userRegisterCensorQuery;
    }

    /**
     * 保存示例
     * @return UserRegisterCensorVO
     */
    public UserRegisterCensorVO saveUserRegisterCensorExample(){
        UserRegisterCensorAddDTO addDTO = this.getUserRegisterCensorAddDTO();
        UserRegisterCensorVO userRegisterCensorVO = userRegisterCensorService.save(addDTO,buildTokenUser());
        return userRegisterCensorVO;
    }


}

